<?php
/**
 * Created by Engineer CuiLiwu.
 * Project: deal.
 * Date: 2018/6/20-14:54
 * License Hangzhou orce Technology Co., Ltd. Copyright © 2018
 */

namespace App\Http\Controllers\Admin\Im;

use App\Http\Controllers\Admin\BaseController;
use Illuminate\Http\Request;

class ImRecordController extends BaseController
{
    protected $api_url = [
        'index' => ['get', 'record'],
        'show' => ['get', 'record/%d'],
        //'delete' => ['delete', 'im/record/%d'],
    ];

    protected $request;

    public function __construct(Request $request)
    {
        $this->request = $request;
    }

    /**
     *
     * */
    public function index()
    {
        //参数部分
        $search_params = $this->request->all(['user_name', 'name']);
        $page = $this->request->get('page', 1);
        $params = [
            'search' => search_params($search_params),
            'searchJoin' => 'and',
            'orderBy'=>'created_at',
            'sortedBy'=>'desc',
            'page' => $page,
//            'with' => 'user'
        ];

        //请求部分
        $ret = http_admin($this->api_url['index'])->send($params);

        //结果处理部分
        $this->httpCodeJudge($ret);
        $data = paginate($this->request, $ret['data']);

        //回填搜索框值
        $data['search_params'] = $search_params;
        return view('Admin.im.record_list', $data);
    }

    public function show($id)
    {
        $ret = http_admin($this->api_url['show'],[$id])->send();

        //结果处理
        $this->httpCodeJudge($ret);
        $data['record'] = $ret['data'];
        return view('Admin.im.record_detail', $data);
    }

    /**
     *  删除IM 用户
     * */
    public function destroy($id){
        return '不允许删除聊天记录';
    }


}